package com.deer.wms.ware.task.config;

import com.deer.wms.project.root.core.result.CommonCode;
import com.deer.wms.project.root.exception.ServiceException;
import com.deer.wms.ware.task.model.SO.SoMaster;
import com.deer.wms.ware.task.model.enums.SoTypeResolveEnum;
import com.deer.wms.ware.task.model.out.OutDetail;
import com.deer.wms.ware.task.model.pushErp.PushErpBean;
import com.deer.wms.ware.task.model.pushErp.beasAssist.BaseAssist;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: xu
 * @Date: 2022/06/17/11:46
 * @Description:
 */
@Component
public class StrategyErpService implements ApplicationContextAware {
    private Map<Integer, PushErpBean> iFileStrategyMap = new ConcurrentHashMap<>();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, PushErpBean> tmepMap = applicationContext.getBeansOfType(PushErpBean.class);
        tmepMap.values().forEach(strategyService -> iFileStrategyMap.put(strategyService.gainFileType(), strategyService));
    }


    public Map<String,String> resolveSo(SoMaster soMaster, List<OutDetail> children , BaseAssist enterAssist) {

        PushErpBean iFileStrategy = iFileStrategyMap.get(soMaster.getSoType());
        if (iFileStrategy != null) {
           return iFileStrategy.getBeanAndPush(soMaster, children, enterAssist);
        }
        return null;
    }

}
